package com.polaris.live.resp.back_resp

import android.os.Parcelable
import com.polaris.live.common.resp.UserDecorationDto
import com.polaris.live.common.resp.UserPerkVo
import com.polaris.live.common.resp.UserResp
import com.polaris.live.common.util.JsonUtils
import com.polaris.live.im.sfs.bean.live.CallSignalingMessage
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.im.sfs.bean.live.payload.AnimationLayersVo
import kotlinx.parcelize.IgnoredOnParcel

/**
 * InfoOtherResp
 *
 * @author Created by 半仙 on 2023/9/22/022 17:19
 */
@kotlinx.parcelize.Parcelize
data class InfoOtherResp(
    /**
     * 性别
     */
    val sex: Int,
    /**
     * 用户id
     */
    val userId: Long,
    /**
     * 用户显示号码
     */
    val userNumber: Long,
    /**
     * 昵称
     */
    val nickname: String,
    /**
     * 用户是否在线
     */
    var online: Int,
    /**
     * 头像
     */
    val avatar: String,
    /**
     * 生日
     */
    val birthday: Long? = null,
    /**
     * 创建时间
     */
    val createTime: Long,
    /**
     * 账户信息
     */
    val account: UserOtherAccountVo,
    /**
     * 标识
     */
    val flag: UserOtherFlagVo,
    /**
     * 用户收到的部分礼物信息
     */
    val gifts: List<UserOtherGiftVo>,
    /**
     * 用户标签
     */
    val labels: List<UserOtherLabelVo>,
    /**
     * 用户相册信息
     */
    val photos: List<UserOtherPhotoVo>,
    /**
     * 资料信息
     */
    val profile: UserOtherProfileVo,
    /**
     * 通话信息
     */
    val call: UserOtherCallVo? = null,
    /**
     * 直播信息
     */
    val live: UserOtherLiveVo? = null,
    /**
     * 封面照
     */
    val coverPhoto: UserOtherCoverPhotoVo? = null,
    /**
     * 用户关系
     */
    val relation: UserOtherRelationVo? = null,
    /**
     * 备注
     */
    val remark: UserOtherRemarkVo? = null,
    /**
     * 用户的勋章信息
     */
    val medals: List<UserMedalVo>? = null,
    /**
     * 装饰展示
     */
    val decoration: UserDecorationDto? = null,
    /**
     * UserPerkVo 用户的靓号信息
     */
    val perk: UserPerkVo? = null,
) : Parcelable {

    /**
     * 最后一次状态变更时间
     */
    @Transient
    @IgnoredOnParcel
    var lastStateTime: Long? = null

}

/**
 * UserOtherAccountVo，他人数值信息
 */
@kotlinx.parcelize.Parcelize
data class UserOtherAccountVo(
    /**
     * 魅力值
     */
    val charms: Long,

    /**
     * 粉丝数
     */
    val fans: Long,

    /**
     * 关注数
     */
    val followers: Long,

    /**
     * 喜欢数
     */
    val likes: Long,

    /**
     * 壕气值
     */
    val richs: Long,

    /**
     * 访客数
     */
    val visits: Long,
) : Parcelable

/**
 * UserOtherCallVo，他人通话信息
 */
@kotlinx.parcelize.Parcelize
data class UserOtherCallVo(
    /**
     * 每分钟价格
     */
    val callPrice: Long,
    /**
     * 实际价格
     */
    val actualPrice: Long,
    /**
     * 是否正在通话中
     */
    var calling: Boolean,
    /**
     * 通话类型
     */
    var callType: Int? = null,
    /**
     * 最后一次通话时间
     */
    var lastCallTime: Long? = null,
) : Parcelable

/**
 * UserOtherCoverPhotoVo，他人直播封面照
 */
@kotlinx.parcelize.Parcelize
data class UserOtherCoverPhotoVo(
    /**
     * 状态 1-审核通过 9-机审中  通过一次后一直为通过用来判断是否展示相册
     */
    val status: Int,
    /**
     * 当前照片审核状态 1-审核通过 9-机审中  null算通过
     */
    val currentStatus: Int?,
    /**
     * 封面图片的url
     */
    val url: String,
) : Parcelable

/**
 * UserOtherFlagVo，他人标识信息
 */
@kotlinx.parcelize.Parcelize
data class UserOtherFlagVo(
    /**
     * 是否官方账号
     */
    val official: Long,
    /**
     * 标签
     */
    val label: List<String>? = null,
    /**
     * 是否被禁言
     */
    val mute: Boolean,
) : Parcelable

/**
 * UserOtherGiftVo，UserOtherGiftVo
 */
@kotlinx.parcelize.Parcelize
data class UserOtherGiftVo(
    /**
     * 礼物id
     */
    val giftId: Long = 0,
    /**
     * 收到的礼物数量
     */
    val number: Long? = null,
    /**
     * 礼物url
     */
    val url: String? = null,
    /**
     * 礼物名称
     */
    val giftName: String? = null,
) : Parcelable

/**
 * UserOtherLabelVo，他人标签信息
 */
@kotlinx.parcelize.Parcelize
data class UserOtherLabelVo(
    /**
     * 标签id
     */
    val labelId: Long,
    /**
     * 标签名称
     */
    val labelName: String,
    /**
     * 数量
     */
    val number: Long,
) : Parcelable

/**
 * UserOtherLiveVo，他人直播信息
 */
@kotlinx.parcelize.Parcelize
data class UserOtherLiveVo(
    /**
     * 直播的流id
     */
    var liveStreamId: String? = null,
    /**
     * 直播类型
     */
    var liveType: Int? = null,
    /**
     * 是否正在直播
     */
    var living: Boolean,
    /**
     * 游戏座位
     */
    var partyGameSite: Int? = null,
    /**
     * 游戏状态
     */
    var partyGameStatus: Int? = null,
    /**
     * 游戏类型
     */
    var partyGameType: Int? = null,
    /**
     * 是否在游戏
     */
    var partyGaming: Int? = null,
    /**
     * 麦位信息
     */
    var partySite: Int? = null,
    /**
     * 状态banner
     */
    var stateBanner: String? = null,
    /**
     * 房间Id
     */
    var roomId: String? = null,
) : Parcelable

/**
 * UserOtherPhotoVo，他人相册
 */
@kotlinx.parcelize.Parcelize
data class UserOtherPhotoVo(
    /**
     * 图片id
     */
    val photoId: Int,
    /**
     * 图片url
     */
    val url: String,
    /**
     * 图片状态 0审核中 1：审核通过
     */
    val status: Int,
) : Parcelable

/**
 * UserOtherProfileVo，他人资料信息
 */
@kotlinx.parcelize.Parcelize
data class UserOtherProfileVo(
    /**
     * 关于我
     */
    val aboutMe: String? = null,

    /**
     * 国家
     */
    val country: String? = null,

    /**
     * 用户系统语言
     */
    val language: String,
    /**
     * 是否相同语言
     */
    val sameLanguage: Boolean,

    /**
     * 第二语言
     */
    val secondLanguage: String? = null,
    /**
     * 用户当前的vip等级
     */
    val vipLevel: Long? = null,
) : Parcelable

/**
 * UserOtherRelationVo，他人与自己的关系
 */
@kotlinx.parcelize.Parcelize
data class UserOtherRelationVo(
    /**
     * 自己是否关注过
     */
    var followed: Boolean,
    /**
     * 自己是否喜欢过
     */
    val liked: Boolean,
    /**
     * 我是否拉黑了对方
     */
    var blocked: Boolean,
) : Parcelable

/**
 * UserOtherRemarkVo，他人备注
 */
@kotlinx.parcelize.Parcelize
data class UserOtherRemarkVo(
    /**
     * 备注
     */
    val remark: String,
) : Parcelable

/**
 * UserMedalVo 用户的勋章信息
 */
@kotlinx.parcelize.Parcelize
data class UserMedalVo(
    /**
     * 勋章id
     */
    val medalId: Long,
    /**
     * 勋章名称
     */
    val name: String,
    /**
     * 勋章描述
     */
    val description: String,
    /**
     * 勋章图片地址
     */
    val photoUrl: String,
    /**
     * 勋章pag地址
     */
    val pagUrl: String? = null,
    /**
     * 勋章获得时间
     */
    val createTime: Long? = null,
    /**
     * 未获取勋章图片地址
     */
    val fallbackPhotoUrl: String,
    /**
     * 跳转标题
     */
    val routerTitle: String? = null,
    /**
     * 跳转路由
     */
    val routerUrl: String? = null,
    /**
     * 替换的动效层  只有在有pag动效的时候才不为null
     */
    val layers: AnimationLayersVo? = null,
) : Parcelable

/**
 * 转换为用户基本信息
 */
fun InfoOtherResp.toUserBasicVo(): UserBasicVo {
    val tempLabel = if (flag.label != null && flag.label?.isNotEmpty() == true) {
        JsonUtils.toJson(flag.label)
    } else {
        null
    }
    return UserBasicVo(
        userId = userId,
        userNumber = userNumber,
        sex = sex,
        avatar = avatar,
        nickname = nickname,
        birthday = birthday,
        createTime = createTime,
        online = online,
        living = if (live?.living == true) 1 else 0,
        liveType = live?.liveType,
        calling = if (call?.calling == true) 1 else 0,
        callType = call?.callType,
        lastCallTime = call?.lastCallTime,
        richs = account.richs,
        charms = account.charms,
        language = profile.language,
        country = profile.country,
        official = flag.official,
        avatarFrame = decoration?.avatarFrame,
        chatBubble = decoration?.chatBubble,
        label = tempLabel,
        vipLevel = profile.vipLevel,
        nicknameColor = decoration?.nicknameColor,
    )
}

fun InfoOtherResp.toDisplayUserBean(): DisplayUserBean {
    return DisplayUserBean(
        actualPrice = call?.actualPrice ?: 0,
        base = this.toUserBasicVo(),
        cover = coverPhoto?.url,
        playStreamId = "",
        stayUser = 0L,
        follow = relation?.followed == true,
        roomId = this.live?.roomId
    )
}

/**
 * 转换为用户基本信息
 */
fun UserResp.toUserBasicVo(): UserBasicVo {
    val tempLabel = if (flag?.label?.isNotEmpty() == true) {
        JsonUtils.toJson(flag?.label)
    } else {
        null
    }
    return UserBasicVo(
        userId = userId ?: 0,
        userNumber = userNumber ?: 0,
        sex = sex,
        avatar = avatar ?: "",
        nickname = nickname ?: "",
        birthday = birthday,
        createTime = createTime ?: 0,
        online = online ?: 0,
        living = live?.living,
        liveType = live?.liveType,
        calling = call?.calling,
        callType = call?.callType,
        lastCallTime = 0,
        richs = account?.richs ?: 0,
        charms = account?.charms ?: 0,
        language = profile?.language,
        country = profile?.country,
        official = flag?.official?.toLong() ?: -1,
        avatarFrame = decoration?.avatarFrame,
        chatBubble = decoration?.chatBubble,
        label = tempLabel,
        vipLevel = profile?.vipLevel,
        nicknameColor = decoration?.nicknameColor,
    )
}

/**
 * 转换为用户基本信息
 */
fun CallSignalingMessage.toUserBasicVo(): UserBasicVo {
    return UserBasicVo(
        userId = sender,
        userNumber = senderNumber,
        sex = sex,
        avatar = avatar,
        nickname = nickname,
        birthday = birthday,
        createTime = createTime ?: 0,
        online = 0,
        living = 0,
        liveType = 0,
        calling = 0,
        callType = 0,
        lastCallTime = 0,
        richs = richs,
        charms = charms,
        language = language,
        country = country,
        official = -1,
        avatarFrame = avatarFrame,
        chatBubble = "",
        vipLevel = vipLevel,
        nicknameColor = nicknameColor,
    )
}
